package com.xzsoft.gdwz.controller;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

public class UserController {
	@RequestMapping("index")
	public String index() {
		return "index";
	}

	@RequestMapping("hello")
	public String hello() {
		return "index1";
	}

	@RequestMapping(value = "/detail/ind", method = { RequestMethod.GET })
	public ModelAndView getDetail() {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("id", "12345678");
		modelAndView.setViewName("index1");
		return modelAndView;
	}

	@RequestMapping(value = "/det/{msg}", method = { RequestMethod.GET })
	public ModelAndView toView(@PathVariable(value="msg") String msg) {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("msg", msg);
		modelAndView.setViewName("index1");
		return modelAndView;
	}
	
	@RequestMapping(value="/*/{name}",method={RequestMethod.GET})
	public ModelAndView helloToSomeone(@PathVariable(value="name") String name){
		ModelAndView view = new ModelAndView();
		view.addObject("name",name);
		view.setViewName("hello");
		return view;
	}
	
	@RequestMapping(value="/getPara",method={RequestMethod.GET})
	public ModelAndView getPara(HttpServletRequest request) throws UnsupportedEncodingException{
		ModelAndView view = new ModelAndView();
		request.setCharacterEncoding("utf-8");
		String name = new String(request.getParameter("name").getBytes("iso-8859-1"), "UTF-8");
		String pass = request.getParameter("pass");
		view.addObject("name",name);
		view.addObject("pass",pass);
		view.setViewName("getParameters");
		return view;
	}
	
	@RequestMapping(value="/list",method={RequestMethod.GET})
	public ModelAndView list(HttpServletRequest request) throws UnsupportedEncodingException{
		ModelAndView view = new ModelAndView();
		view.setViewName("/demo/list");
		return view;
	}
}
